import { request } from '.././network/request'
let token = localStorage.getItem('token')

// 登录
export function fetchLoginInfo(config) {
  console.log(config)
  return request({
    url: '/admin/login',
    method: 'POST',
    data: config.data,
  })
}

// 侧边栏信息
export function fetchMenuList() {
  return request({
    url: '/menu/treeList',
    headers: {
      Authorization: token,
    },
  })
}

// 获取login token
export function fetchLogout() {
  return request({
    url: '/admin/logout',
    method: 'POST',
  })
}

// 获取商品列表
export function fetchGoodsList(page_num, page_size) {
  return request({
    url: '/product/list',
    headers: {
      Authorization: token,
    },
    params: { pageNum: page_num, pageSize: page_size },
  })
}

// 编辑商品列表单条数据
export function fetchGoodsSKU(pid) {
  return request({
    url: `/sku/${pid}`,
    headers: {
      Authorization: token,
    },
  })
}

// 商品列表 模糊查询
export function fetchGoodsSearch() {
  return request({
    url: '/product/simpleList',
    headers: {
      Authorization: token,
    },
  })
}

// 级联选择器 分类
export function fetchGoodsClassification() {
  return request({
    url: '/productAttribute/category/list/withAttr',
    headers: {
      Authorization: token,
    },
  })
}

// 级联选择器 商品品牌
export function fetchGoodsBrand() {
  return request({
    url: '/brand/listAll',
    headers: {
      Authorization: token,
    },
  })
}

// 商品分类
export function fetchCommodityClassification(ids) {
  return request({
    url: `/productCategory/list/${ids}`,
    headers: {
      Authorization: token,
    },
  })
}

// 商品分类编辑
export function fetchCommodityClassificationEdit(id) {
  return request({
    url: `/productCategory/${id}`,
    headers: {
      Authorization: token,
    },
  })
}

// 商品类型
export function fetchGoodsType(page_num, page_size) {
  return request({
    url: '/productAttribute/category/list',
    headers: {
      Authorization: token,
    },
    params: {
      pageNum: page_num,
      pageSize: page_size,
    },
  })
}
// 商品品牌管理
export function fetchGoodsBrandList(page_num, page_size = 10) {
  return request({
    url: '/brand/list',
    headers: {
      Authorization: token,
    },
    params: {
      pageNum: page_num,
      pageSize: page_size,
    },
  })
}
// 商品品牌管理编辑
export function fetchGoodsBrandListEdit(id) {
  return request({
    url: `/brand/${id}`,
    headers: {
      Authorization: token,
    },
  })
}
// 订单列表
export function fetchOrderList(page_num, page_size = 10) {
  return request({
    url: '/order/list',
    headers: {
      Authorization: token,
    },
    params: {
      pageNum: page_num,
      pageSize: page_size,
    },
  })
}

// 订单列表 时间
export function mkfsTime(time) {
  let lastIndexOf = time.lastIndexOf('.')
  return time.slice(0, lastIndexOf).split('T').join(' ')
}

// 订单详情
export function fetchOrderDetails(id) {
  return request({
    url: `/order/${id}`,
    headers: {
      Authorization: token,
    },
  })
}
